<?php
/**
 * @version        $Id$
 * @author         master@xuewl.com
 * @copyright      Copyright (c) 2007 - 2013, Chongqing Zero Technology Co. Ltd.
 * @link           http://www.xuewl.com
**/
namespace Document\Controller;
use \Admin\Controller\InitController;
define('MODULE_CACHE', DATA_PATH.'caches_model/');
Class CashController extends InitController {
      public function _initialize() {
       parent::_initialize();
        $this->db = D('Cash');
        $this->user_db = D('Member');
        
    }
    
    public function index(){
    $pagecurr = max(1,I('page',0,'intval')); 
    $pagesize = 10;
    $cash=$this->db->order('cash_time DESC')->page($pagecurr,$pagesize)->select();
    $count = $this->db->count(); 
    $pages = page($count, 10);
    include $this->admin_tpl('cash_list');
    	
    }
    
    public function update($id = 0){
    	if($id){
    		$info=$this->db->where(array('cash_id'=>$id))->find();
    		 include $this->admin_tpl('cash_update');
    	}
    	
    	if($_POST){
    		$info = I('info');
    		if($info['cash_status'] == 1){
    			$apply_coin=$info['apply_coin'];
    			$u_coin=$this->user_db->where(array('userid'=>$info['userid']))->find();
    			if ($apply_coin>$u_coin['u_coin']){
    				$this->error('操作失败！,该用户帐户余额不足');
    			}
    			docrsh($info['userid'], $apply_coin);
    			if ($info['cash_type'] == 'alipay'){
    				$type="支付宝提现".$info['apply_money'];
    			}
    	 		if ($info['cash_type'] == 'tenpay'){
    				$type="财付通提现".$info['apply_money'];
    			}
    			if ($info['cash_type'] == 'bank'){
    				$type="银行提现".$info['apply_money'];
    			}
    			score_change($info['userid'],$type,$apply_coin,'u_coin',0);
    			$now_coin=$u_coin['u_coin']-$apply_coin;
    			$result=$this->user_db->where(array('userid'=>$info['userid']))->save(array('u_coin'=>$now_coin));
    			$time=$this->db->where(array('cash_id'=>$info['id']))->save(array('handle'=>time(),'cash_status'=>$info['cash_status']));
    			$this->success('操作成功', 'javascript:close_dialog();', 2);
    			
    		}
    	
    	}
    }
    
 	//删除操作
    public function delete(){
        $id = $_GET['id'];
        $result = $this->db->delete($id);
        if($result)
           $this->success('操作成功', 'javascript:close_dialog();', 2);

    }
    
}